/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2012 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.auto.ibatis;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.TransGroovyMappingDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.TransGroovyMappingDO;
import java.util.List;
import org.springframework.dao.DataAccessException;
import java.util.Map;
import java.util.HashMap;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.TransGroovyMappingDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_trans_groovy_mapping.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisTransGroovyMappingDAO extends SqlMapClientDaoSupport implements
                                                                       TransGroovyMappingDAO {

    /**
     *  Query DB table <tt>sgw_trans_groovy_mapping</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, channel_system_id, out_trans_code_id, template_id, gateway_mode, gmt_create, gmt_modified from sgw_trans_groovy_mapping</tt>
     *
     *	@return List<TransGroovyMappingDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<TransGroovyMappingDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-TRANS-GROOVY-MAPPING-LOAD-ALL", null);

    }

    /**
     *  Query DB table <tt>sgw_trans_groovy_mapping</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select p.id, p.channel_system_id, p.out_trans_code_id, p.template_id, p.gateway_mode, p.gmt_create, p.gmt_modified from sgw_trans_groovy_mapping p where (p.channel_system_id IN (select distinct channel_system_id from sgw_cluster_mapping where (cluster_id = ?)))</tt>
     *
     *	@param clusterId
     *	@return List<TransGroovyMappingDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<TransGroovyMappingDO> loadByClusterId(String clusterId) throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-TRANS-GROOVY-MAPPING-LOAD-BY-CLUSTER-ID",
            clusterId);

    }

    /**
     *  Insert one <tt>TransGroovyMappingDO</tt> object to DB table <tt>sgw_trans_groovy_mapping</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_trans_groovy_mapping(id,channel_system_id,out_trans_code_id,template_id,gateway_mode,gmt_create,gmt_modified) values (?, ?, ?, ?, ?, sysdate, sysdate)</tt>
     *
     *	@param transGroovyMapping
     *	@return long
     *	@throws DataAccessException
     */
    public long insert(TransGroovyMappingDO transGroovyMapping) throws DataAccessException {
        if (transGroovyMapping == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-TRANS-GROOVY-MAPPING-INSERT", transGroovyMapping);

        return transGroovyMapping.getId();
    }

    /**
     *  Query DB table <tt>sgw_trans_groovy_mapping</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, channel_system_id, out_trans_code_id, template_id, gateway_mode, gmt_create, gmt_modified from sgw_trans_groovy_mapping where ((template_id = ?) AND (channel_system_id = ?))</tt>
     *
     *	@param templateId
     *	@param channelSystemId
     *	@return List<TransGroovyMappingDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public List<TransGroovyMappingDO> select(int templateId, String channelSystemId)
                                                                                    throws DataAccessException {
        Map param = new HashMap();
        if (templateId != -1) {
            param.put("templateId", new Integer(templateId));
        }

        param.put("channelSystemId", channelSystemId);

        return getSqlMapClientTemplate().queryForList("MS-TRANS-GROOVY-MAPPING-SELECT", param);

    }

    /**
     *  Update DB table <tt>sgw_trans_groovy_mapping</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_trans_groovy_mapping set channel_system_id=?, out_trans_code_id=?, template_id=?, gateway_mode=?, gmt_modified=sysdate where (id = ?)</tt>
     *
     *	@param channelSystemId
     *	@param outTransCodeId
     *	@param templateId
     *	@param gatewayMode
     *	@param id
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public int update(String channelSystemId, String outTransCodeId, int templateId,
                      String gatewayMode, long id) throws DataAccessException {
        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("outTransCodeId", outTransCodeId);
        param.put("templateId", new Integer(templateId));
        param.put("gatewayMode", gatewayMode);
        param.put("id", new Long(id));

        return getSqlMapClientTemplate().update("MS-TRANS-GROOVY-MAPPING-UPDATE", param);
    }

}